package com.dmx.cep.action.contentManage;

import java.util.Date;

import com.dmx.cep.entity.AdiImportTask;
import com.dmx.cep.service.ContentService;
import com.dmx.fw.web.struts2.action.CommonQueryAction;

public class AdiImportTaskAction extends CommonQueryAction{
	private Integer q_status;
	
	private Long taskId;
	
	private ContentService contentService;
	
	private String errorMessage;
	
	public String execute() throws Exception{
        this.busiId="searchAdiImportTask";
		
        if("resetTask".equals(this.act)){
        	return resetTask();
        }
        if("viewMessage".equals(this.act)){
        	return viewMessage();
        }
        if(q_status!=null&&q_status.intValue()!=0){
        	this.sortField="LASTUPDATE_TIME";
        	this.sortMode="desc";
        }
        
		return super.execute();
	}

	
	public String viewMessage() throws Exception{
		
		AdiImportTask task=(AdiImportTask)contentService.getObject(AdiImportTask.class, taskId);
		
		errorMessage=task.getMessage();
		
		return "viewMessage";
	}
	
	public String resetTask() throws Exception{
		
		AdiImportTask task=(AdiImportTask)contentService.getObject(AdiImportTask.class, taskId);
		
		task.setStatus(0);
		
		task.setLastUpdateTime(new Date());
		
		contentService.saveObject(task);
		
		this.setSuccessinfo(this.getText("info.resetSuccess"));
		
		return "list";
	}
	
	public Integer getQ_status() {
		return q_status;
	}

	public void setQ_status(Integer q_status) {
		this.q_status = q_status;
	}


	public Long getTaskId() {
		return taskId;
	}


	public void setTaskId(Long taskId) {
		this.taskId = taskId;
	}


	public ContentService getContentService() {
		return contentService;
	}


	public void setContentService(ContentService contentService) {
		this.contentService = contentService;
	}


	public String getErrorMessage() {
		return errorMessage;
	}


	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
}
